package io.renren.modules.xm.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.xm.entity.GiftProjectEntity;
import io.renren.modules.xm.service.GiftProjectService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 赠送项目
 *
 * @author liuyonggang
 * @email 544872316@qq.com
 * @date 2018-07-08 15:01:35
 */
@RestController
@RequestMapping("xm/giftproject")
public class GiftProjectController extends AbstractController {
    @Autowired
    private GiftProjectService giftProjectService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("xm:giftproject:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = giftProjectService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("xm:giftproject:info")
    public R info(@PathVariable("id") Integer id){
        GiftProjectEntity giftProject = giftProjectService.selectById(id);

        return R.ok().put("giftProject", giftProject);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("xm:giftproject:save")
    public R save(@RequestBody GiftProjectEntity giftProject){
        giftProjectService.insert(giftProject);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("xm:giftproject:update")
    public R update(@RequestBody GiftProjectEntity giftProject){
        ValidatorUtils.validateEntity(giftProject);
        giftProjectService.updateAllColumnById(giftProject);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("xm:giftproject:delete")
    public R delete(@RequestBody Integer[] ids){
        giftProjectService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
